Some resources

Resources and Links for Plotly and ggplot2.

Here are the links for the resources mentioned in this lecture:

Plotly:

https://plot.ly

Package to install:

install.packages('plotly')

Reference for gglotly() examples:

https://plot.ly/ggplot2/

Reference for full ggplotly example documentation:

http://ropensci.github.io/plotly-test-table/tables/0e3d5ca144d27d8416318824c1b6ec1421a51045/index.html

Background

We can use the open source library called ‘plotly’ to convert our ggplot2 graphics into interactive images.

Let’s install the ‘plotly’ library and call all necessary libraries for our project:

# install.packages("plotly")

# call the libraries
library(ggplot2)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout

Create a ggplot2 plot

Let’s create a scatterplot from the ‘mtcars’ built-in dataset.

pl <- ggplot(mtcars,aes(mpg,wt)) + geom_point()
pl

Create an interactive plot

Use ggplotly() to convert the non-interactive plot into an interactive one.

gpl <- ggplotly(pl)
gpl

Refer to the online documentation on ‘ggplotly’ for sample codes and examples of various statistical charts.